|
|
|
|
|
|
|
The Data control discussion in this chapter walks you through an example that you can follow along with. You'll create a simple application that allows you to browse the names of book authors stored in BIBLIO.MDB, which is a sample database provided with Visual Basic. To begin the sample project, start a new Visual Basic Standard EXE project and add a Data control to the form. Set the Data control's Name property to dtaMain and its Caption property to Authors. Also, make sure it is wide enough to display its caption. Figure 25.2 shows the form with this control added. |
|
|
|
|
| |
|
|
|
|
You also can add code to your program to change the Data control's caption to reflect information in the current record, such as a person's name. |
|
|
|
|
|
|
|
|
|
|
Figure 25.2
Draw the Data control on your
form, and set its caption appropriately. |
|
|
|
|
|
|
|
|
The Two Required Properties |
|
|
|
|
|
|
|
|
After you place the Data control on your form, you need to make the connection between the Data control and the actual database. You do so by setting some of the Data control's properties. Although several properties can affect the way a Data control interacts with the database, only two properties are required to establish the link to a Jet database: the DatabaseName and RecordSource properties. Specifying these two properties tells the Data control what information to retrieve from the database and causes the Data control to create a recordset that allows nonexclusive, read/write access to the data. |
|
|
|
|
|
|
|
|
|
The DatabaseName property is not the same as the Name property mentioned earlier. The Name property specifies the name of the Data control object. This name references the object in code. The DatabaseName property specifies the path name of the physical database that the Data control is accessing.  |
|
|
|
|
|
|
|
|
|
|
Data controls can be set up to work with many different types of databases. This example, however, will concentrate on connecting to Microsoft Jet databases. For Jet databases, the DatabaseName property is the name of the database file. To enter the name, select the DatabaseName property from the Properties window, and type the database's fully qualified pathname. |
|
|
|
|
|
|
|
|
The easiest way to locate a database is by browsing. Just click the ellipsis button ( . . . ) at the right of the DatabaseName property input line to display the DatabaseName dialog box, as |
|
|
|
|
|